



<script src="__TMPL__/public/assets/js/jquery-1.10.2.min.js"></script>
<script src="__TMPL__/public/assets/layui/layui.js"></script>
<script src="__STATIC__/js/laydate.js"></script>
<link  href="__TMPL__/public/assets/layui/css/layui.css" rel="stylesheet">
<script src="__STATIC__/js/echarts.min.js"></script>


<div class="wrap js-check-wrap">

    <form class="layui-form" action="" style="display: flex;padding-top: 20px">
        <div class="layui-form-item">
            <label class="layui-form-label">用户</label>
            <div class="layui-input-block">
                <input type="text" id="title" lay-verify="title" autocomplete="off" placeholder="请输入用户名称/电话/id" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <select name="interest" id="status" lay-filter="aihao">
                    <option value=''>全部</option>
                    <option value='0'  >普通</option>
                    <option value='2'  >负责人</option>
                    <option value='1'  >加盟商</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" id="selectval" lay-filter="demo1">查看</button>
                <a href="" class="layui-btn ">重置</a>
            </div>
        </div>
    </form>


    <table class="table table-hover table-bordered">

        <table class="layui-hide" id="test" lay-filter="test"></table>

        <script type="text/html" id="barDemo">
            {{#  if(d.team_fa == 1){ }}
            <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="quxiao">取消</a>
            {{#  } }}

            {{#  if(d.team_fa != 1){ }}
            <a class="layui-btn layui-btn-xs " lay-event="setadmin">管理员</a>
            {{#  } }}

            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs" lay-event="seeorder">推广信息</a>
        </script>

        <!--    自定义    -->
        <script type="text/html" id="titleTpl">

            {{#  if(d.level == 2){ }} 负责人{{#  } }}
            {{#  if(d.level == 1){ }} 加盟商{{#  } }}
            {{#  if(d.level == 0){ }} 普通{{#  } }}

        </script>

        <script type="text/html" id="titleTpl1">
            {{#  if(d.kf == 0){ }} 无权限{{#  } }}
            {{#  if(d.kf == 1){ }} 入库管理{{#  } }}
        </script>

        <script>

            layui.use('table', function(){
                var table = layui.table;
                var curl="{:url('getalllist')}";

                var tableIns =table.render({
                    elem: '#test' ,
                    url:curl,
                    method: 'post',
                    toolbar: '#toolbarDemo',
                    title: '用户数据表',
                    cols: [[
                        {field:'id', title:'ID', width:80, fixed: 'left'}
                        ,{field:'name', title:'用户名',edit: 'text'}
                        ,{field:'mobile', title:'电话'}
                        ,{field:'team_title', title:'团队'}
                        ,{field:'agentid_name', title:'推荐人'}
                        ,{field:'level', title:'类型', templet: '#titleTpl'}
                        ,{field:'kf', title:'入库', templet: '#titleTpl1'}
                        ,{fixed: 'right', title:'操作', toolbar: '#barDemo',width: 220}
                    ]]
                    ,page: true
                });


                $("#selectval").click(function (){

                    var username=$("#title").val();
                    var level=$("#status").val();

                    tableIns.reload({
                        where: { key:username ,level:level} ,
                        page: { curr: 1  }
                    });

                })

                // user/adminIndex/seelogs

                //表格工具行事件
                table.on('tool(test)', function(obj){
                    var data = obj.data;

                    if(obj.event === 'adming'){

                        var curl="{:url('seting')}?id="+data.id;

                        layer.open({
                            type: 2,
                            area: ['700px', '500px'],
                            content: curl,
                            success:function (){
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            }
                        });
                    }

                    if(obj.event === 'edit'){

                        var curl="{:url('seting')}?id="+data.id;

                        layer.open({
                            type: 2,
                            area: ['700px', '500px'],
                            content: curl,
                            success:function (){
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            }
                        });
                    }

                    if(obj.event === 'seeorder'){

                        var curl="{:url('seelogs')}?id="+data.id;

                        layer.open({
                            type: 2,
                            area: ['900px', '600px'],
                            content: curl,
                            success:function (){
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            }
                        });
                    }
                    //设置为管理
                    if (obj.event === 'setadmin'){

                        var curl="{:url('setadmin')}";

                        layer.confirm('设置为管理？', function(index){
                            $.ajax({
                                url: curl,
                                data:{'id':data.id},
                                type:'post',
                                success:function (ret){
                                    location.reload();
                                }
                            })
                        });

                    }

                    //设置为管理
                    if (obj.event === 'quxiao'){

                        var curl="{:url('quxiao')}";

                        layer.confirm('设置为管理？', function(index){
                            $.ajax({
                                url: curl,
                                data:{'id':data.id},
                                type:'post',
                                success:function (ret){
                                    location.reload();
                                }
                            })
                        });

                    }


                });


            });
        </script>


    </table>

</div>
<script src="__STATIC__/js/admin.js"></script>
